import 'package:flutter/material.dart';
import 'package:example/base/base_page_widget.dart';
import 'package:example/widget/my_image.dart';
import 'package:example/widget/my_navbar.dart';
import 'package:get/get.dart';

import '../../../widget/none_scroll_behavior.dart';
import 'preview_image_logic.dart';

class PreviewImagePage extends BasePageWidget {
  final logic = Get.find<PreviewImageLogic>();
  final state = Get.find<PreviewImageLogic>().state;

  PreviewImagePage({super.key});

  @override
  Widget initView(BuildContext context) {
    return Scaffold(
      appBar: MyNavBar(
        centerTitle: "预览图片",
        titleColor: Colors.black,
        backImgColor: Colors.black,
        backgroundColor: Colors.white,
      ),
      backgroundColor: Colors.black,
      body: SafeArea(
        child: GetBuilder<PreviewImageLogic>(
          id: state.idPage,
          builder: (c) {
            return ScrollConfiguration(
              behavior: NoneScrollBehavior(),
              child: PageView.builder(
                controller: state.pageController,
                physics: state.isPagePhysics()
                    ? const PageScrollPhysics()
                    : const NeverScrollableScrollPhysics(),
                itemBuilder: (BuildContext context, int index) {
                  return InteractiveViewer(
                    transformationController: state.transformationController,
                    onInteractionEnd: (e) {
                      logic.updatePage();
                    },
                    child: MyImage(
                      path: state.urls![index],
                      fit: BoxFit.contain,
                      showPlaceholder: true,
                    ),
                  );
                },
                itemCount: state.urls?.length ?? 0,
              ),
            );
          },
        ),
      ),
    );
  }
}
